<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        /**
         * 数据类型转换通常指将其他数据类型转成 字符串 数字 布尔值
         * 数据类型转换有两种: 强制转换(显式转换) 和 自动转换(隐式转换)
         * 
         * 强制转换(显式转换): 其他类型 转成 数字
         * 
         * Number(val)将val转成数字类型
         * '' 空串转换成0   null转换成0  undefined转换成NaN  []转换成0
         * 
         * parseInt() 和 parseFloat() 也可以将数字或字符串转成数字
         * '' 空串 、 布尔值、null、undefined、object、function、[]、全部转换成NaN
         * [7,8,9]转换成第一个数字7
         * 
        */

        var str1 = '';// 空串               
        var str2 = 'hello';// 非空串
        var num1 = 0;// 0
        var num2 = 123;// 非0
        var num3 = NaN;
        var boo1 = true;
        var boo2 = false;
        var nul = null;
        var und = undefined;
        var obj = { a: 1, b: 2 };
        var fun = function () { };
        var arr1 = [];
        var arr2 = [6];
        var arr3 = [7, 8, 9];


        console.log(Number(str1));//0
        console.log(Number(str2));//NaN
        console.log(Number(num1));//0
        console.log(Number(num2));//123
        console.log(Number(num3));//NaN
        console.log(Number(boo1));//1
        console.log(Number(boo2));//0
        console.log(Number(nul));//0
        console.log(Number(und));//NaN
        console.log(Number(obj));//NaN
        console.log(Number(fun));//NaN
        console.log(Number(arr1));//0
        console.log(Number(arr2));//6
        console.log(Number(arr3));//NaN

        console.log(parseInt(str1));//NaN
        console.log(parseInt(str2));//NaN
        console.log(parseInt(num1));//0
        console.log(parseInt(num2));//123
        console.log(parseInt(num3));//NaN
        console.log(parseInt(boo1));//NaN
        console.log(parseInt(boo2));//NaN
        console.log(parseInt(nul));//NaN
        console.log(parseInt(und));//NaN
        console.log(parseInt(obj));//NaN
        console.log(parseInt(fun));//NaN
        console.log(parseInt(arr1));//NaN
        console.log(parseInt(arr2));//6
        console.log(parseInt(arr3));//7
    </script>
</body>
</html>